package WSS;
/**
 * 
 */

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import Http.ConnectionString;
import Objetos.Producto;

/**
 * @author ARMGARCES
 * @version 1.0
 */
public class WssInventario {

	private static String serviceUrl;
	private static String serviceNamespace;
	private static String soapAction;

	
	/**
	 * 
	 * @param codigo
	 * @return
	 * @throws Exception 
	 */
	public static Producto getProducto(final Object codigo) throws Exception{
		try{			
			/* El valor 0 indica que el servicio a solicitarse sera getProducto */
			serviceUrl 		= "http://digamaracay3.dynalias.com:8080/WSS/Inventario?wsdl";
			serviceNamespace= "http://digamaracay3.dynalias.com:8080/WSS/Inventario";
			soapAction 		= "http://digamaracay3.dynalias.com:8080/WSS/getProducto";
			String methodName = "getProducto";
			
			serviceUrl 		 += ConnectionString.getConnectionString();
			soapAction		 += ConnectionString.getConnectionString();
			SoapObject rpc = new SoapObject(serviceNamespace, methodName);
			
			rpc.addProperty("codigo",codigo.toString());
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			
			envelope.bodyOut = rpc;
			envelope.dotNet = true;
			envelope.encodingStyle = SoapSerializationEnvelope.ENC;
		
			HttpTransport ht = new HttpTransport(serviceUrl);
			ht.debug = true;
			ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 
			//**************************************
			
        	ht.call(soapAction, envelope); 
        	
        	if(envelope.getResponse() !=null){
        		SoapObject _soap = (SoapObject) envelope.getResponse();
        		Producto producto = new Producto(_soap);
				return producto;
        		
			}else{
				return null;
			}
		}catch(final Exception e){
			throw e;
		}
	}
	
}
